<template>
  <div class="radio-group-wrap">
    <slot></slot>
  </div>
</template>
<script>
export default {
  name: 'JRadioGroup',
  props: {
    value: {
      type: [String, Object]
    }
  },
  mounted () {
    if (this.value) {
      this.dispatch(this.value, true);
    }
    this.$on('change', this.radioChange);
  },
  methods: {
    dispatch (data, isChange) {
      this.$children.forEach(item => {
        const temp = item;
        temp.isChecked = true;
        temp.checkIsActive(data, isChange);
      });
    },
    radioChange (data) {
      this.$emit('input', data.norm_name);
      this.dispatch(data.norm_name, false);
    }
  }
};
</script>
